/**
 * @class $$.Observable
 * 简单的事件类。
 */
$$.Observable = function(ObservableList){
	if(ObservableList){
		this.addObservable(ObservableList);
	}
}
$$.Observable.prototype = {
	toString: function(){
		return 'Observable';
	}
	,addObservable : function(){
		// 创建事件结构
		this.Observables = this.Observables || {};
		for(var i = 0 ;i < arguments.length; i++){
			this.Observables[String(arguments[i]).toLowerCase()] = [];
		}		
	}
	,addListener: function(ObservableName, ObservableHandler, scope, option){
		var thatObservable = this.Observables[ObservableName.toLowerCase()];
		if(!thatObservable){
			throw "No such Observable";
		}if(!ObservableHandler){
			throw 'No passing Function!';
		}else{
			// ObservableObj
			thatObservable.push({
				 fn		: ObservableHandler
				,scope  : scope || $$.emptyObj
				,cfg 	: option
			});		
		}
	}
	,hasObservable  : function(ObservableName){
		return !!(this.Observables[ObservableName.toLowerCase()]);
	}
	,fireObservable : function(ObservableName){
		var thatObservable = this.Observables[ObservableName.toLowerCase()]
			
		if(!thatObservable){
			throw "No such Observable";
		}else{
			var ObservableObj, args = Array.prototype.slice.call(arguments, 1);
			for(var i = 0 ;i < thatObservable.length; i++){
				ObservableObj = thatObservable[i];
				ObservableObj.fn.apply(ObservableObj.scope, args);
			}
			return true;
		}
	}
};
// shorthands
$$.Observable.prototype.on = $$.Observable.prototype.addListener;